<template>
    <div style="max-height: 450px;">
        <div class="article-list" v-for="(item, index) in new1" :key="index">
            <el-row>
                <el-col :span="18">
                    <div class="text-box">
                        <el-link type="primary" :underline="false" :href="openArticleLike(item.id)" target="_blank">
                            <div class="text-title">{{ item.title }}</div>
                        </el-link>
                        <el-text truncated line-clamp="3" class="text-content" style="word-wrap: break-word;">
                            {{ item.content }}
                        </el-text>
                        <div class="text-date"><el-icon>
                                <Timer />
                            </el-icon>{{ item.view_date }}</div>
                    </div>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script setup lang='ts'>

import { getArticle } from '@/api/home2';
import { getimage } from '@/api/image';
import { onMounted, ref } from 'vue'

const new1 = ref()

const getAnimen1 = async () => {
    const res = await getArticle()
    new1.value = res.data.data
    for (let i = 0; i < new1.value.length; i++) {
        new1.value[i].img = await getimage(new1.value[i].img)
    }
    // console.log(new1);

}

onMounted(() => {
    getAnimen1()
})

const openArticleLike = (id) => {

    return '/article/' + id
}
</script>

<style scoped>
.card {
    margin-bottom: 10px;
}

.article-list {
    padding: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid #e61919;
}

.image-box {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
}

.article-image {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
}

.text-box {
    padding: 0 10px;
}

.text-title {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-content {
    font-size: 14px;
    color: #666;
    margin-bottom: 8px;
}

.text-date {
    font-size: 12px;
    color: #999;
    display: flex;
    align-items: center;
}

.text-date .el-icon {
    margin-right: 4px;
}
</style>